package main
import (
	"fmt"
)
type Income interface {
	calculate() int
	source() string
}
type FixedBilling struct{
	projectName string
	biddedAmount int
}
type TimeAndMaterial struct {
	projectName string
	noOfHours int
	hourlyRate int
}
// 新增收益流
type Advertisement  struct {
	adName string
	CPC int
	noOfClicks int
}
func (fb FixedBilling) calculate() int {
	return fb.biddedAmount
}
func (fb FixedBilling) source() string {
	return fb.projectName
}
func (tm TimeAndMaterial) calculate() int {
	return tm.noOfHours * tm.hourlyRate
}
func (tm TimeAndMaterial) source() string {
	return tm.projectName
}
// // 新增收益流
func (a Advertisement) calculate() int {
	return a.CPC * a.noOfClicks
}
func (a Advertisement) source() string {
	return a.adName
}
func calculateNetIncome(ic []Income) {
	var neticome int = 0
	for _, income := range ic {
		fmt.Printf("Income From %s = $%d\n", income.source(), income.calculate())
		neticome += income.calculate()
	}
	fmt.Printf("Net income of organisation = $%d", neticome)
}

// 28. 多态
func main(){
	project1 := FixedBilling{projectName: "Project 111", biddedAmount: 1111111}
	project2 := FixedBilling{projectName: "Project 222", biddedAmount: 222222}
	project3 := TimeAndMaterial{projectName: "Project 333", noOfHours: 160, hourlyRate: 33}
	bannerAd1 := Advertisement{adName:"yanghao 项目1", CPC: 2, noOfClicks: 444444}
	bannerAd2 := Advertisement{adName:"yanghao 项目2", CPC: 3, noOfClicks: 5555}
	incomeStreams := []Income{project1, project2, project3, bannerAd1, bannerAd2}
	calculateNetIncome(incomeStreams)

}
